/**
 * 
 */
package com.thor.palmmall.rest.device.repair.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.chart.converter.APictureConverter;
import com.thor.palmmall.rest.common.ADeviceRepairMaterialConverter;
import com.thor.palmmall.rest.common.AOperateInfoConverter;
import com.thor.palmmall.rest.common.AProcessRecordConverter;
import com.thor.palmmall.rest.common.ASourceBillConverter;
import com.thor.palmmall.rest.common.AWorkOrderConverter;
import com.thor.palmmall.rest.device.repair.ADeviceRepair;
import com.thor.palmmall.spi.device.repair.SDeviceRepair;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class ADeviceRepairConverter implements Converter<SDeviceRepair, ADeviceRepair> {

  public static ADeviceRepairConverter getInstance() {
    if (instance == null)
      instance = new ADeviceRepairConverter();
    return instance;
  }

  private static ADeviceRepairConverter instance;

  private ADeviceRepairConverter() {
  }

  @Override
  public ADeviceRepair convert(SDeviceRepair source) {
    if (source == null) {
      return null;
    }
    ADeviceRepair target = new ADeviceRepair();

    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(AOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(AOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setAbortMsg(source.getAbortMsg());
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setBpmState(source.getBpmState());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setCategory(UCN.newInstance(source.getCategory()));
    target.setApplicant(UCN.newInstance(source.getApplicant()));
    target.setRepairDate(source.getRepairDate());
    target.setRepairBeginTime(source.getRepairBeginTime());
    target.setRepairEndTime(source.getRepairEndTime());
    target.setReportDate(source.getReportDate());
    target.setRepairor(UCN.newInstance(source.getRepairor()));
    target.setTelephone(source.getTelephone());
    target.setArtificialFee(source.getArtificialFee());
    target.setPartsFee(source.getPartsFee());
    target.setSourceBill(ASourceBillConverter.getInstance().convert(source.getSourceBill()));
    target.setSituation(source.getSituation());
    target.setProcesses(
        ConverterUtil.convert(source.getProcesses(), AProcessRecordConverter.getInstance()));
    target.setTenantEvaluation(source.getTenantEvaluation());
    target.setDevice(UCN.newInstance(source.getDevice()));
    target.setPlace(source.getPlace());
    target.setEvaluation(source.getEvaluation());
    target.setEvaluateUser(UCN.newInstance(source.getEvaluateUser()));
    target.setEvaluateTime(source.getEvaluateTime());
    target.setMaterials(
        ConverterUtil.convert(source.getMaterials(), ADeviceRepairMaterialConverter.getInstance()));
    target
        .setPictures(ConverterUtil.convert(source.getPictures(), APictureConverter.getInstance()));
    target.setAfterPictures(
        ConverterUtil.convert(source.getAfterPictures(), APictureConverter.getInstance()));

    target.setItems(new ArrayList<KV>());
    target.getItems().addAll(source.getItems());
    
    target.setType(source.getType());
    target.setWorkOrder(AWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setRemark(source.getRemark());
    target.setHandler(source.getHandler());

    return target;
  }

}
